package com.cskaoyan.service;

import com.cskaoyan.bean.BaseData;
import com.cskaoyan.bean.BaseParam;
import com.cskaoyan.bean.comment.MarketComment;
import com.cskaoyan.bean.comment.MarketCommentExample;
import com.cskaoyan.bean.goods.MarketGoods;
import com.cskaoyan.mapper.MarketCommentMapper;
import com.cskaoyan.util.PageUtil;
import com.github.pagehelper.PageInfo;
import org.apache.ibatis.annotations.Select;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Hu
 * @create 2021-09-17 16:15
 * @Description
 */

@Service
public class CommentServiceImpl implements CommentService {


    @Autowired
    MarketCommentMapper commentMapper;

    @Override
    public BaseData<MarketComment> list(BaseParam baseParam, Integer userId, Integer valueId) {
        PageUtil.start(baseParam);
        MarketCommentExample marketCommentExample = new MarketCommentExample();
        marketCommentExample.setOrderByClause(baseParam.getSort() + " " + baseParam.getOrder());
        MarketCommentExample.Criteria criteria = marketCommentExample.createCriteria();
        criteria.andDeletedEqualTo(false);
        if (userId != null && !"".equals(userId)) {
            criteria.andUserIdEqualTo(userId);
        }
        if (valueId != null && !"".equals(valueId)) {
            criteria.andValueIdEqualTo(valueId);
        }
        List<MarketComment> marketComments = commentMapper.selectByExample(marketCommentExample);
        PageInfo<MarketComment> pageInfo = new PageInfo<>(marketComments);
        BaseData<MarketComment> data = new BaseData<>(pageInfo, marketComments);

        return data;
    }

    @Override
    public void delete(Integer id) {
        commentMapper.deleteByIdInLogic(id);
    }
}
